package com.xcf.controller.business.common;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xcf.controller.base.BaseController;
import com.xcf.service.business.common.ticketfee.TicketFeeService;
import com.xcf.util.PageData;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
@Controller
@RequestMapping(value="/ticket")
public class TicketFeeController  extends BaseController{
	@Resource
	protected TicketFeeService ticketfeeservice;
	String menuUrl="ticket/fee";//菜单地址(权限用) 
@RequestMapping(value="/fee")
public  ModelAndView ticket(){
	ModelAndView mv = new ModelAndView();
	mv.setViewName("/business/common/openticketfee/open_ticket_fee");
	return mv;	
}

@RequestMapping(value="/list")
public void list(HttpServletResponse response) throws Exception{
	PageData pd = new PageData();
	pd = this.getPageData();
	List<PageData> list =ticketfeeservice.serch(pd);
	JSONArray array = new JSONArray();
	for (PageData data : list) {
		JSONObject ob = new JSONObject();
		ob.put("id", data.get("id"));
		ob.put("fee_name", data.getString("fee_name"));
		ob.put("tax_rate", data.get("tax_rate"));
		array.add(ob);
	}
	response.setContentType("text/html; charset=utf-8");         
    response.getWriter().write("{"+"\""+"total"+"\""+":"+"\""+"10"+"\""+","+"\""+"rows"+"\""+":"+array+"}");
}
//修改
@RequestMapping(value="/updite")
@ResponseBody
public String updtie() throws Exception{
	PageData pd = new PageData();
	pd = this.getPageData();
	ticketfeeservice.updite(pd);
	return null;	
}
//新增
@RequestMapping(value="/add")
@ResponseBody
public String add() throws Exception{
PageData pd = new PageData();
pd = this.getPageData();
ticketfeeservice.save(pd);
return null;
	

}
//删除
	@RequestMapping(value="deleteU")
	@ResponseBody
	
		public String deleteinfo() throws Exception{
			PageData pd = new PageData();
			pd = this.getPageData();
			String data = pd.getString("array");
					JSONArray items = JSONArray.fromObject(data);
					for(int i=0,size=items.size();i<size;i++){
						JSONObject item = items.getJSONObject(i);
						String id = item.getString("id").trim();
						PageData pdq = new PageData();
						pdq.put("id", id);
						ticketfeeservice.delete(pdq);
				}
					return null;
					
		}
}